<template>
  <el-dialog v-if="value" :visible="value" title="修改信息" width="50%" @close="$emit('input', false)">
    <el-form
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
      :model="ruleForm"
      :rules="rules"
    >
      <el-form-item label="用户名" prop="username">
        <el-input v-model="ruleForm.username" type="text" autocomplete="off" />
      </el-form-item>
      <el-form-item label="邮箱" prop="email">
        <el-input v-model="ruleForm.email" type="text" autocomplete="off" />
      </el-form-item>
      <el-form-item label="手机号" prop="mobile">
        <el-input v-model.number="ruleForm.mobile" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="$emit('input', false)">取 消</el-button>
      <el-button
        type="primary"
        @click="handleEdit(ruleForm.id)"
      >确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { getUserIdInfo } from '@/api/user.js'

export default {
  props: {
    value: {
      type: Boolean,
      required: true
    },

    ruleForm: {
      type: Object,
      required: true
    }

  },
  data() {
    return {

      rules: {
        username: [
          { required: true, message: '请输入活动名称', trigger: 'blur' },
          { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ],
        email: [
          { required: true, message: '请输入邮箱', trigger: 'blur' }
        ],
        mobile: [
          { required: true, message: '请输入手机号', trigger: 'change' },
          { min: 11, max: 11, message: '长度为字符', trigger: 'blur' }
        ]
      }
    }
  },

  created() {},

  methods: {
    // 编辑用户
    async handleEdit(id) {
      this.dialogVisible = true
      try {
        await getUserIdInfo(id)
        this.$emit('input', false)

        this.$message.success('修改成功')
      } catch (err) {
        console.log(err)
      }
    },
    handleClose() {
      console.log(11)
    }
  }
}
</script>

<style scoped lang="scss"></style>
